Real numbers are any numbers that may be represented as finite or infinite decimals and may be used to measure continuous quantities, such as in the physcial sciences. The set of real numbers includes all rational numbers and all irrational numbers. Computers may approximate real numbers with rational numbers using a floating point number or fixed-point number representation or notation. In computer hardware, a number is stored in a binary word, which is a fixed-length sequence of binary digits (1's and 0's). A data type refers to the way in which data is classified, characterized, or represented. A binary number may be represented by a fixed-point data type or floating-point data type. A fixed-point number representation is a real data type for a number that has a fixed number of digits after the decimal, i.e., the decimal or binary point is fixed. In a floating-point data type, a real number is represented by an integer or fixed-point number multiplied by a base (typically a base 2 in computers) to some integer power, and the decimal point is referred to as floating.
A fixed-point data type may be characterized by the word size in bits, the binary point, and whether it is signed or unsigned. Additionally, fixed-point data types may be integers, fractions, or general fixed-point numbers. One of the differences between fixed-point and floating-point data types is the default binary point, which is the means by which fixed-point numbers are scaled. A fixed-point number may be encoded in a computer using a slope-bias encoding scheme. For example, a real number R may be encoded in a computer using a binary integer or quantized value Q by the following equation: R=S*Q+B, where S and B are real numbers. S is referred to as the slope and B as the bias. Q is computed by solving the equation and then rounding the result to an integer value. The slope S typically may be a number of the form 2E because numbers of this form can be easily manipulated in hardware.
Binary numbers can also be represented as floating-point data types. A floating-point number in an Institute of Electrical & Electronic Engineers (IEEE) standard representation may approximately be stored as a [E,Q] pair where B is zero. This type of representation is called floating-point because E changes or floats depending on the values to be represented. In fixed-point representation, only the value Q is stored and the values for S and B do not change. As a result, fixed-point computations more often have overflow or underflow problems.
For both fixed-point and floating-point data types, word sizes are fixed at a set number of bits. However, the range of fixed-point values may be less than floating-point values with the same word size because the decimal point is fixed in the fixed-point representation. In order to prevent overflow or unreasonable quantization errors, fixed-point values are scaled. Fixed-point operations can be done with integer math support in a processor. However, floating-point math typically requires specialized hardware to obtain desired performance. As such, fixed-point is often used where the cost of hardware is an important consideration. The logic circuits of fixed-point hardware are much less complicated than floating-point hardware, which typically translates into a smaller size with less power consumption. Furthermore, fixed-point calculations generally use less memory and less processor time to perform.
Because the slope and bias are fixed in fixed-point operations, programming languages supporting fixed-point math may specify what the slope and bias for an output will be when multiple inputs with different slopes and biases are used together. For example, what should the slope of X+Y be if X has a slope of 2−4 and Y has a slope of 2−5. Obtaining fixed-point results with good precision while avoiding an overflow or underflow condition depends on making the appropriate slope and bias choice. Therefore, languages may have rules that specify this behavior. Unfortunately, any one set of rules will not be adequate for all applications. Compiling a language with rules that can change poses a technical difficulty when generating code for a processor, such as an embedded processor. A goal of a fixed-point implementation is to run efficiently on less expensive hardware. However, with rules that change, the fixed-point data type of a result may be difficult to determine.